package com.ruoyi.web.controller;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.SysCourse;
import com.ruoyi.system.service.ISysCourseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSingleQuestion;
import com.ruoyi.system.service.ISysSingleQuestionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单选题Controller
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@Controller
@RequestMapping("/system/sysSingleQuestion")
public class SysSingleQuestionController extends BaseController
{
    private String prefix = "system/sysSingleQuestion";

    @Autowired
    private ISysSingleQuestionService sysSingleQuestionService;

    @Autowired
    private ISysCourseService sysCourseService;

    @RequiresPermissions("system:sysSingleQuestion:view")
    @GetMapping()
    public String sysSingleQuestion()
    {
        return prefix + "/sysSingleQuestion";
    }

    /**
     * 查询单选题列表
     */
    @RequiresPermissions("system:sysSingleQuestion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysSingleQuestion sysSingleQuestion)
    {
        startPage();
        List<SysSingleQuestion> list = sysSingleQuestionService.selectSysSingleQuestionList(sysSingleQuestion);
        return getDataTable(list);
    }

    /**
     * 导出单选题列表
     */
    @RequiresPermissions("system:sysSingleQuestion:export")
    @Log(title = "单选题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysSingleQuestion sysSingleQuestion)
    {
        List<SysSingleQuestion> list = sysSingleQuestionService.selectSysSingleQuestionList(sysSingleQuestion);
        ExcelUtil<SysSingleQuestion> util = new ExcelUtil<SysSingleQuestion>(SysSingleQuestion.class);
        return util.exportExcel(list, "单选题数据");
    }

    /**
     * 新增单选题
     */
    @RequiresPermissions("system:sysSingleQuestion:add")
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        SysCourse sysCourse = new SysCourse();
        sysCourse.setCreateBy(ShiroUtils.getLoginName());
        List<SysCourse> sysCourses = sysCourseService.selectSysCourseList(sysCourse);
        mmap.put("sysCourses", sysCourses);
        return prefix + "/add";
    }

    /**
     * 新增保存单选题
     */
    @RequiresPermissions("system:sysSingleQuestion:add")
    @Log(title = "单选题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysSingleQuestion sysSingleQuestion)
    {
        return toAjax(sysSingleQuestionService.insertSysSingleQuestion(sysSingleQuestion));
    }

    /**
     * 修改单选题
     */
    @RequiresPermissions("system:sysSingleQuestion:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysSingleQuestion sysSingleQuestion = sysSingleQuestionService.selectSysSingleQuestionById(id);
        mmap.put("sysSingleQuestion", sysSingleQuestion);
        return prefix + "/edit";
    }

    /**
     * 修改保存单选题
     */
    @RequiresPermissions("system:sysSingleQuestion:edit")
    @Log(title = "单选题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysSingleQuestion sysSingleQuestion)
    {
        return toAjax(sysSingleQuestionService.updateSysSingleQuestion(sysSingleQuestion));
    }

    /**
     * 删除单选题
     */
    @RequiresPermissions("system:sysSingleQuestion:remove")
    @Log(title = "单选题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysSingleQuestionService.deleteSysSingleQuestionByIds(ids));
    }
}
